<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>CTF题目集管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});

		<%--function selectCtf(ctfSetAttribute){--%>
			<%--$.ajax({--%>
				<%--type: "POST",--%>
				<%--url: "${ctx}/resource/resourceCtfSet/findCtfSubjectByAttribute",--%>
				<%--data: {--%>
					<%--resourceCtfSubject:findAllTrainProgramNameId.options[findAllTrainProgramNameId.selectedIndex].value--%>
				<%--},--%>
				<%--success:function(json){--%>
					<%--$(".resetDuallist").empty();--%>
					<%--var list = json.dataObj;--%>
					<%--for(var i=0;i<list.resourceCtfSubjectList.length;i++)--%>
					<%--{--%>
						<%--$("#resourceCtfSubjectList").append("<option value='"+ list.resourceCtfSubjectList[i].id+"'>"+list.resourceCtfSubjectList[i].ctfSubjectName+"</option>");--%>
					<%--}--%>
					<%--$(".resetDuallist").bootstrapDualListbox('refresh');--%>
				<%--},--%>
				<%--error:function(){--%>
					<%--alertx("error");--%>
				<%--}--%>
			<%--});--%>
		<%--}--%>
		function checkValidate()
		{
			var ctfSetName=document.getElementById("ctfSetName").value;
			var duallist=document.getElementById("duallist").value;
			//判断是否为空
			if(ctfSetName==""||ctfSetName==null)
			{
				window.alertx("请输入Ctf题目集名称！");
				return false;
			}
			if(duallist==""||duallist==null)
			{
				window.alertx("请选择题目！");
				return false;
			}
		}
		function selectAttribute(attribute){
			$.ajax({
				type: "POST",
				url: "${ctx}/resource/resourceCtfSet/findCtfSetListByAttribute",
				data: {
					attribute:attribute.options[attribute.selectedIndex].value
				},
				success:function(json){
					console.log(json);
					$(".resetDuallist").empty();
					var list = json.dataObj;
					for(var i=0;i<list.length;i++)
					{

						$("#duallist").append("<option value='"+ list[i].id+"'>"+list[i].ctfSubjectName+"</option>");
						console.log(list[i].ctfSubjectName);
					}
					$(".resetDuallist").bootstrapDualListbox('refresh');
				},
				error:function(){
					alertx("error");
				}
			});
		}
	</script>
	<script type="text/javascript" src="${path}/js/common/jquery.min.js"></script>
	<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" type="text/css" media="all">
	<%--<link rel="stylesheet" href="${path}/css/common/bootstrap.min.css" rel="stylesheet" type="text/css" media="all"/>--%>
	<link rel="stylesheet" href="${path}/css/common/bootstrap-duallistbox.css" rel="stylesheet" type="text/css"/>
	<script type="text/javascript" src="${path}/js/common/jquery.bootstrap-duallistbox.js"></script>
	<style>
		.control-label{font-weight: normal;}
		#ctfSetName{ height: 30px;}
	</style>

</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/resource/resourceCtfSet/">CTF题目集列表</a></li>
		<li class="active"><a href="${ctx}/resource/resourceCtfSet/form?id=${resourceCtfSet.id}">CTF题目集<c:choose><c:when test="${not empty type}">复制</c:when><c:otherwise><shiro:hasPermission name="resource:resourceCtfSet:edit">${not empty resourceCtfSet.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="resource:resourceCtfSet:edit">查看</shiro:lacksPermission></c:otherwise></c:choose></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="resourceCtfSet" action="${ctx}/resource/resourceCtfSet/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<input type="hidden" name="type" id="type" value="${type}">
		<sys:message content="${message}"/>

		<div class="control-group">
			<label class="control-label">CTF题目集名称：</label>
			<div class="controls">
				<form:input id="ctfSetName" name="ctfSetName" path="ctfSetName" htmlEscape="false" maxlength="64" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">CTF题目集属性：</label>
			<div class="controls">

				<select id="ctfSetAttribute" name="ctfSetAttribute" class="input-xlarge required">
					<c:choose>
						<c:when test="${isSuperAdmin=='false'}">
							<option value="0" selected>${fns:getDictLabel("0",'resource_coursesystem_attribute',"无")}</option>
						</c:when>
						<c:otherwise>
					<%--<option value="0" selected>${fns:getDictLabel("0",'resource_ctf_set_attribute',"无")}</option>--%>
					<%--<form:options items="${fns:getDictList('resource_ctf_set_attribute')}" itemLabel="label" itemValue="value" htmlEscape="false"/>--%>
					<c:forEach var="attribute" items="${fns:getDictList('resource_ctf_set_attribute')}">
						<option value="${fns:getDictValue(attribute,'resource_ctf_set_attribute',"")}" <c:if test="${fns:getDictValue(attribute,'resource_ctf_set_attribute','')==resourceCtfSet.ctfSetAttribute}">selected</c:if>>${attribute}</option>
					</c:forEach>
					</c:otherwise>
				</c:choose>
				</select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">选择题目：</label>
			<div class="controls">
				<div class="container"></div>
					<%--<%@ include file="maskProgramFormTest.jsp"%>--%>
				<div class="col-lg-10 col-md-9 col-sm-9 col-xs-12">
					<select  multiple="multiple" size="10" id="duallist" name="duallist" class="resetDuallist">
						<c:set var="index" value="0" />
						<c:forEach var="resourceCtfSubject" items="${resourceCtfSubjectList}">
							<option value="${resourceCtfSubject.id}" <c:if test="${resourceCtfSubject.isChoose=='true'}">selected</c:if>>${resourceCtfSubject.ctfSubjectName}</option>
							<c:if test="${resourceQuestion.environmentId !=null}">
								<c:set var="index" value="${index+1}" />
							</c:if>
						</c:forEach>
						<input type="hidden" name="index" id="index" value="${index}">
						<%--${index}--%>
					</select>
						<%--<c:forEach var="resourceQuestion" items="${resourceQuestionList}">--%>
						<%--<input type="text" value="${resourceQuestion.isChoose}" maxlength="64" class="input-xlarge required"/>--%>
						<%--</c:forEach>--%>
				</div>
				<span class="help-inline" ><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注信息：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="resource:resourceCtfSet:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存" onclick=" return checkValidate()"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
	<script>
		var demo1 = $('select[name="duallist"]').bootstrapDualListbox();
		$("#demoform").submit(function() {
			alert($('[name="duallist"]').val());
			return false;
		});
	</script>
</body>
</html>